import asyncio
from typing import Optional
from contextlib import AsyncExitStack

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

from anthropic import Anthropic
from dotenv import load_dotenv

import os, sys
current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_path+'/..')
from core.providers import OllamaProvider
from core.weather import MCPClient, SimpleMCPClient, SSEMCPClient

load_dotenv()  # load environment variables from .env

async def main():
    # client = MCPClient()
    server_name="weather"
    client= SSEMCPClient(
        server_name=server_name,
        url="http://0.0.0.0:8080/sse"
    )
    """
    if len(sys.argv) < 2:
        print("Usage: python client.py <path_to_server_script>")
        sys.exit(1)
        
    server_script_path=sys.argv[1]
    client = SimpleMCPClient(
                server_name=server_name,
                command="python",
                args=[server_script_path],
                env=None )
    """
    try:
        # await client.connect_to_server(sys.argv[1])
        await client.start()
        
        await client.chat_loop()
    finally:
        await client.cleanup()

if __name__ == "__main__":
    import sys
    asyncio.run(main())
